const UNIQUE_KEY = 'LOWCODE_EDTIOR_'
const str2json = (str) => {
  let json = null
  try {
    json = JSON.parse(str)
  } catch (e) {
    console.error('str2json error ', e)
  }
  return json
}
const getStoreKey = (key) => {
  return `${UNIQUE_KEY}${key}`
}
export const getItem = (key) => {
  const _key = getStoreKey(key)
  const text = window.localStorage.getItem(_key)
  return str2json(text)
}

export const saveItem = (key, value) => {
  console.log('缓存数据', +new Date(), key)
  const _key = getStoreKey(key)
  window.localStorage.setItem(_key, JSON.stringify(value))
}

export const removeItem = (key) => {
  const _key = getStoreKey(key)
  window.localStorage.removeItem(_key)
}
